package caixinyu.demo77777.controller;

import caixinyu.demo77777.entity.Customer;
import caixinyu.demo77777.service.CustomerServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CustomerController {
    @Autowired
    CustomerServcie customerServcie;
    //添加客户信息
    @GetMapping("/save")
    public String saveCustomer(){
        Customer customer=new Customer();
        customer.setJobNo("J00354");
        customer.setName("张三");
        customer.setDepartment("软件学院");
        int result=customerServcie.saveCustomer(customer);
        if(result>0){
            return "添加员工成功！";
        }else{
            return "添加员工失败！";
        }
    }
    //根据ID查询客户信息
    @GetMapping("/getCustomer/{id}")
    public Customer getCustomerById(
            @PathVariable Integer id){
        return customerServcie.getCustomerById(id);
    }

    //获取所有角色信息
    @GetMapping("/getAllCustomer")
    public List<Customer> getAllCustomer(){
        return customerServcie.getAllCustomer();
    }

    //修改角色信息
    @GetMapping("/updateCustomer")
    public String updateCustomer(Customer customer){
        customer.setId(1);
        customer.setJobNo("J00111");
        customer.setName("李四");
        customer.setDepartment("信息学院");
        int result = customerServcie.updateCustomer(customer);
        if (result > 0) {
            return "修改员工成功啦！";
        } else {
            return "修改员工失败啦！";
        }

    }

    //根据ID删除角色信息
    @GetMapping("/deleteCustomer/{id}")
    public String deleteCustomerById(@PathVariable Integer id){
        int result = customerServcie.deleteCustomerById(id);
        if (result > 0) {
            return "删除角色成功啦！";
        } else {
            return "删除角色失败！";
        }
    }

}
